<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				工单服务
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="top clearfix">
				<view class="left fl clearfix">
					<view class="mess fl" @click="qiehuan(1)">
						<view :class="[attrIndex==1?'active':'']">待处理</view>
						<text class="dian" v-if="attrIndex == 1"></text>
					</view>
					<view class="mess mess1 fl" @click="qiehuan(2)">
						<view :class="[attrIndex==2?'active':'']">已处理</view>
						<text class="dian" v-if="attrIndex == 2"></text>
					</view>
				</view>
				<view class="right fr" @click="topage('/subpackageA/work/add')">
					<view class="name">新增工单</view>
				</view>
			</view>
		</view>
		<view class="content" v-if="list.length != 0">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="top">
					<view class="title" v-if="item.attr == 1">分润问题</view>
					<view class="title" v-if="item.attr == 2">设备问题</view>
					<view class="title" v-if="item.attr == 3">修改手机号</view>
				</view>
				<view class="center">
					<view class="desc">标题：<text class="color">{{item.title}}</text></view>
					<view class="desc" v-if="item.danhao != null">订单号：{{item.danhao}}</view>
					<view class="desc" v-if="item.shebei_sn != null">设备SN：{{item.shebei_sn}}</view>
					<view class="desc">内容：{{item.description}}</view>
					<view class="desc">图片：</view>
					<view class="image">
						<image :src="item.image"></image>
					</view>
					<view class="desc">时间：{{item.create_time}}</view>
				</view>
				<view class="huifu" @click="huifu(index)" v-if="role_id == 1 && item.status == 1">回复</view>
				<view class="center centerhf" v-if="item.status == 2">
					<view class="desc">回复内容：{{item.hfcontent}}</view>
					<view class="desc">时间：{{item.hf_time}}</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
		
		<view class="beijing" v-if="hidden" @click="huifu"></view>
		<view class="tankuang" v-if="hidden">
			<view class="content">
				<view class="title">回复</view>
				<view class="form">
					<textarea placeholder="请输入回复内容(必填)" v-model="hfcontent"></textarea>
					<view class="submit" @click="submit">提交</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				hidden: false,
				list: [],
				attrIndex: 1,
				page: 1,
				pageSize: 10,
				total: 0,
				hf_id: '',
				hfcontent: '',
				role_id: '',
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.role_id = uni.getStorageSync('role_id');
		},
		onShow() {
			this.total = 0;
			this.page = 1;
			this.list = [];
			this.getList(this.attrIndex, this.page, this.pageSize);
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page = this.page + 1;
		
				this.getList(this.attrIndex, this.page, this.pageSize);
			}
		},
		methods: {
			getList(attrIndex, page, pageSize) {
				this.request({
					url: '/xcx/worklist',
					data: {
						agent_id: uni.getStorageSync('agent_id'),
						role_id: this.role_id,
						attr: attrIndex,
						page: page,
						pageSize: pageSize,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.total = res.data.data.total;
						this.list = this.list.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			qiehuan(index){
				this.attrIndex = index;
				this.page = 1;
				this.total = 0;
				this.list = [];
				
				this.getList(this.attrIndex, this.page, this.pageSize);
			},
			huifu(index){
				this.hidden = !this.hidden;
				
				this.hf_id = this.list[index].id;
			},
			submit(){
				let that = this;
				let hfcontent = this.hfcontent;
				
				if(hfcontent == ''){
					uni.showToast({
						title: '内容不能为空',
						icon: 'none'
					})
					return false;
				}
				
				this.request({
					url: '/xcx/workedit',
					data: {
						hfcontent: hfcontent,
						id: this.hf_id,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						uni.showToast({
							title: '回复成功',
							icon: 'none'
						})
						
						that.hidden = !that.hidden;
						that.attrIndex = 2;
						that.page = 1;
						that.total = 0;
						that.list = [];
						
						that.getList(that.attrIndex, that.page, that.pageSize);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss">
	page{
		background: #f9f9ff;
	}
	
	.equipment {
		width: 100%;
		margin: 0 auto;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;
			position: relative;
		
			.top{
				.left {
					.mess {
						height: 48rpx;
						line-height: 48rpx;
						text-align: center;
			
						view {
							font-size: 24rpx;
							color: #333333;
						}
			
						.dian {
							width: 8rpx;
							height: 8rpx;
							background: #5C88FA;
							display: block;
							border-radius: 50%;
							margin: 0 auto;
						}
			
						.active {
							font-size: 32rpx;
							color: #333333;
							font-weight: 700;
							margin-left: 0;
						}
					}
			
					.mess1 {
						margin-left: 20rpx;
					}
				}
				
				.right {
					width: 124rpx;
					height: 36rpx;
					line-height: 36rpx;
					text-align: center;
					background: #FFFFFF;
					border-radius: 24rpx;
					margin-top: 6rpx;
							
					.name {
						font-size: 24rpx;
						color: #333333;
					}
				}
			}
		}
		
		.content{
			width: 100%;
			padding: 0 40rpx;
			box-sizing: border-box;
			margin-top: -200rpx;
			position: absolute;
			
			.list{
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 26rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
				
				.top{
					width: 100%;
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 20rpx;
					
					image{
						width: 72rpx;
						height: 72rpx;
						margin-right: 20rpx;
					}
					
					.title{
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
					}
					
					.money{
						font-size: 28rpx;
						color: #8B8CFF;
						margin-right: 8rpx;
						font-weight: 700;
					}
				}
				
				.center{
					width: 96%;
					margin: 0 auto;
					margin-top: 20rpx;
					
					.desc{
						width: 90%;
						font-size: 24rpx;
						color: #333333;
						line-height: 44rpx;
					}
					
					.color{
						font-size: 24rpx;
						color: #5C88FA;
					}
					
					.image{
						margin-top: 20rpx;
						
						image{
							width: 100rpx;
							height: 100rpx;
							display: inline-block;
							margin-right: 20rpx;
						}
					}
				}
				
				.huifu{
					width: 240rpx;
					margin: 0 auto;
					text-align: center;
					height: 72rpx;
					line-height: 72rpx;
					background: linear-gradient(90deg, #65bdfc, #398ef8);
					border-radius: 36rpx;
					border-top-left-radius: 0;
					border-bottom-left-radius: 42rpx;
					color: #FFFFFF;
					font-size: 32rpx;
				}
			}
		}
		
		.empty{
			width: 100%;
			margin: 20rpx auto 0;
			text-align: center;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
		
		.beijing{
			position: fixed;
			width: 100%;
			height: 100%;
			top: 0;
			left: 0;
			background: #000000;
			opacity: 0.5;
		}
		
		.tankuang{
			position: fixed;
			width: 80%;
			top: 50%;
			left: 10%;
			
			.content{
				width: 100%;
				background: #ffffff;
				padding-bottom: 30rpx;
				border-radius: 20rpx;
				
				.title{
					width: 100%;
					padding-top: 30rpx;
					text-align: center;
					font-size: 36rpx;
					color: #000000;
					font-weight: 600;
				}
				
				.form{
					width: 86%;
					margin: 0 auto;
					margin-top: 50rpx;
					
					textarea{
						height: 180rpx;
						width: 100%;
						color: #838383;
						background: #f9f9f9;
						font-size: 30rpx;
						padding: 3%;
						box-sizing: border-box;
					}
					
					.submit{
						width: 100%;
						background: linear-gradient(90deg, #65bdfc, #398ef8);
						border-radius: 45rpx;
						border-top-left-radius: 0;
						border-bottom-left-radius: 50rpx;
						color: #ffffff;
						font-size: 30rpx;
						height: 90rpx;
						line-height: 90rpx;
						text-align: center;
						margin-top: 60rpx;
					}
				}
			}
		}
	}
</style>